package com.sky.controller.admin.statistics;

import com.sky.result.Result;
import com.sky.service.BorrowingTrendService;
import com.sky.service.DashboardService;
import com.sky.vo.BorrowingTrend7daysVO;
import com.sky.vo.CategoryStatVO;
import com.sky.vo.DashboardCoreMetricsVO;
import com.sky.vo.PopularBookVO;
import com.sky.vo.ReaderBehaviorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 综合数据面板统计相关接口
 */
@RestController
@RequestMapping("/admin/statistics")
@Api(tags = "综合数据面板相关接口")
@Slf4j
public class DashboardController {
    
    @Autowired
    private DashboardService dashboardService;

    @Autowired
    private BorrowingTrendService borrowingTrendService;

    /**
     * 获取核心指标数据
     */
    @GetMapping("/dashboard/core-metrics")
    @ApiOperation("获取核心指标数据")
    public Result<DashboardCoreMetricsVO> getCoreMetrics() {
        log.info("获取仪表盘核心指标数据");
        DashboardCoreMetricsVO coreMetrics = dashboardService.getCoreMetrics();
        return Result.success(coreMetrics);
    }

    /**
     * 获取最近7天的借阅趋势数据
     * @return 借阅趋势数据
     */
    @GetMapping("/borrowing-trend")
    @ApiOperation("获取借阅趋势数据")
    public Result<BorrowingTrend7daysVO> getBorrowingTrend() {
        log.info("获取最近7天借阅趋势数据");
        BorrowingTrend7daysVO trendVO = borrowingTrendService.getBorrowingTrend7days();
        return Result.success(trendVO);
    }

    /**
     * 获取图书分类占比统计数据
     * @return 分类统计数据列表
     */
    @GetMapping("/category/proportion")
    @ApiOperation("获取图书分类占比统计")
    public Result<List<CategoryStatVO>> getCategoryStats() {
        log.info("获取图书分类占比统计数据");
        List<CategoryStatVO> categoryStats = dashboardService.getCategoryStats();
        return Result.success(categoryStats);
    }

    /**
     * 获取热门图书TOP5列表
     * @return 热门图书列表
     */
    @GetMapping("/popular-booksTOP5")
    @ApiOperation("获取热门图书TOP5列表")
    public Result<List<PopularBookVO>> getPopularBooksTOP5() {
        log.info("获取热门图书TOP5列表");
        List<PopularBookVO> popularBooks = dashboardService.getPopularBooks();
        return Result.success(popularBooks);
    }

    /**
     * 获取本周读者活跃度数据
     * @return 读者活跃度数据
     */
    @GetMapping("/reader-behavior")
    @ApiOperation("获取读者活跃度数据")
    public Result<ReaderBehaviorVO> getReaderBehavior() {
        log.info("获取本周读者活跃度数据");
        ReaderBehaviorVO behaviorVO = dashboardService.getReaderBehavior();
        return Result.success(behaviorVO);
    }
} 